package com.library.controller;

import com.library.entity.BorrowRecord;
import com.library.service.BorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/borrows")
public class BorrowController {
    
    @Autowired
    private BorrowService borrowService;
    
    @PostMapping
    public boolean borrowBook(@RequestBody BorrowRecord record) {
        return borrowService.borrowBook(record);
    }
    
    @PostMapping("/{id}/return")
    public boolean returnBook(@PathVariable Integer id) {
        return borrowService.returnBook(id);
    }
    
    @GetMapping("/user/{userId}")
    public List<BorrowRecord> getUserBorrows(@PathVariable Integer userId) {
        return borrowService.findByUserId(userId);
    }
    
    @GetMapping
    public List<BorrowRecord> getAllBorrows() {
        return borrowService.findAll();
    }
} 